import Vue from "vue"
import VueRouter from "vue-router"

Vue.use(VueRouter)

const router = new VueRouter({
    routes: [
        {
            path: "/",
            component: () =>import("../pages/home"),
            meta: {
                footshow: true,
                
            }
        },
        {
            path: "/register",
            name: "Register",
            component: () =>import("../pages/register"),
            meta: {
                footshow: false
            }
        },
        {
            path: "/login",
            name: "Login",
            component: () =>import("../pages/login"),
            meta: {
                footshow: false
            }
        },
        {
            path: "/user",
            name: "User",
            component: () =>import("../pages/user/"), // 路由懒加载
            meta: {
                footshow: true
            }
        },
        {
            path: "/detail/:id",
            name: "Detail",
            component: () =>import("../pages/detail/"), // 路由懒加载
            meta: {
                footshow: true
            }
        },
        {
            path: "/cart",
            name: "Cart",
            component: () =>import("../pages/cart"),
            meta: {
                footshow: true
            },
            beforeEnter: (to, from, next) => {
                var isLogined = localStorage.getItem("token") || "";
                if (!isLogined) {//没有登录
                    next("/login");
                } else {
                    next();//写了这个 其他页面才能放行 这样其他页面才能实现切换自如
                }
            },
        },
        {
            path: "/fenlei",
            name: "Fenlei",
            component: () =>import("../pages/fenlei"),
            meta: {
                footshow: true
            }
        },
        {
            path: "/home",
            name: "Home",
            component: () =>import("../pages/home"),
            meta: {
                footshow: true
            }
        },
        {
            path: "/order",
            name: "Order",
            component: () =>import("../pages/order"),
            meta: {
                footshow: true,
                keepAlive: true,
            }
        },
       
       
    ]
})

export default router